﻿@{
    var menus = new[]
        {
            new { LinkText="Home", ActionName="Index",ControllerName="Home",Roles="All"  },
            new { LinkText="About", ActionName="About",ControllerName="Home",Roles="Anonymous"  },
            new { LinkText="Contact", ActionName="Contact",ControllerName="Home",Roles="Anonymous" },
            new { LinkText="Dashboard", ActionName="Index",ControllerName="Admin",Roles="Administrator"  }
        };
}

<ul id="menu">
@if (HttpContext.Current.User.Identity.IsAuthenticated)
{
    String[] roles = Roles.GetRolesForUser();
    var links = from item in menus
                where item.Roles.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries)
                .Any(x => roles.Contains(x) || x == "All")
                select item;
    foreach (var link in links)
    {
        @: <li> @Html.ActionLink(link.LinkText, link.ActionName,link.ControllerName)</li>
    }
}
else{
    var links = from item in menus
                where item.Roles.Split(new String[]{","},StringSplitOptions.RemoveEmptyEntries)
                .Any(x=>new String[]{"All","Anonymous"}.Contains(x))      
                select item;
     foreach ( var link in links){     
         @: <li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName)</li>         
     }
}
</ul> 